import Vue from 'vue'
import VueRouter from 'vue-router'


// 获取原型对象push函数
const originalPush = VueRouter.prototype.push
// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace
// 修改原型对象中的push函数
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace (location) {
  return originalReplace.call(this, location).catch(err => err)
}


Vue.use(VueRouter)


const routes = [
  {
    path: '/',
    redirect: 'home'
  },

  //前台
  {
    path: '/',
    component: () => import('../views/home/header.vue'),
    children: [
      {
        path: '/login',
        name: 'login',
        component: () => import('../views/login.vue')
      },
      {
        path: '/register',
        name: 'register',
        component: () => import('../views/register.vue')
      },
      {
        //音乐首页
        path: '/home',
        name: 'home',
        component: () => import('../views/view/music/musicHome.vue')
      },
      {
        //歌曲页面
        path: '/searchSong',
        name: 'searchSong',
        component: () => import('../views/view/music/searchSong.vue')
      },
    ]
  },
  //后台
  {
    path: '/',
    component: () => import('../views/home/HomeView.vue'),
    children: [
      {
        //音乐数据界面
        path: '/musicData',
        name: 'musicData',
        component: () => import('../views/view/data/musicData.vue'),
        meta: {
          shovalues: true
        }
      },
      {
        //音乐数据界面
        path: 'allMusic',
        name: 'allMusic',
        component: () => import('../views/manage/allMusic.vue')
      },
      {
        //音乐歌手数据界面
        path: 'allArtist',
        name: 'allArtist',
        component: () => import('../views/manage/allArtist.vue')
      },
      {
        //用户设置
        path: 'userSetting',
        name: 'userSetting',
        component: () => import('../views/manage/userInfo/userSetting.vue')
      },
      {
        //用户设置
        path: 'userList',
        name: 'userList',
        component: () => import('../views/manage/userInfo/userList.vue')
      }
    ]
  },
  {
    //用户记录
    path: '/userInfo',
    name: 'userInfo',
    component: () => import('../views/view/interface/userInfo.vue')
  },
  {
    //歌单页面
    path: '/type',
    name: 'type',
    component: () => import('../views/view/music/playType.vue')
  },
  {
    //歌曲页面
    path: '/song',
    name: 'song',
    component: () => import('../views/view/music/playSong.vue')
  },
  {
    //播放器页面
    path: '/audio',
    name: 'audio',
    component: () => import('../views/view/music/playAudio.vue')
  },


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


export default router
